// 单例模式: 一个类只能有一个实例化对象并提供全局访问

let Alert = (function(){
    let instance, dom;

    function createDom(){
        let dom = document.createElement('div')
        dom.style.display = 'none'
        document.body.append(dom)

        return dom
    }

    let Single = (function(){
        let instance;

        return  function(fn){
            return instance || (instance = fn.apply(this, arguments))
        }
    })();

    function Alert(content){

        instance = instance || (this instanceof Alert?this : new(content))

        instance.init(content)
        return instance
    }
    Alert.prototype.init = function(content){
        dom = Single(createDom)
        dom.innerHTML = content;
        dom.style.display = 'block'
    }
    Alert.prototype.hide = function(){
        dom.style.display = 'none'
    }
    return Alert

})();

let a = new Alert('我是A元素')

let b = new Alert('我是B元素')

console.log(a, b , a == b)